package com.project.ToDone;
//package com.androidhive.googlemaps;

import java.util.ArrayList;
 
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
 
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;


/**
 * The AddItemizedOverlay class allows us to place markers
 * on the map.
 * @author Paco Swift
 *
 */
public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem>{

	private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
	 
    private Context context;

    /**
     * Just the default constructor
     * 
     * @param defaultMarker
     */
    public AddItemizedOverlay(Drawable defaultMarker) {
         super(boundCenterBottom(defaultMarker));
    }

    /**
     * Constructor that allows for clicking
     * 
     * @param defaultMarker
     * @param context
     */
    public AddItemizedOverlay(Drawable defaultMarker, Context context) {
         this(defaultMarker);
         this.context = context;
    }
    
  

    
    
    /**
     * Creates this item
     * 
     */
    @Override
    protected OverlayItem createItem(int i) {
       return mapOverlays.get(i);
    }
    
    /**
     * Gets size of list
     * 
     */
    @Override
    public int size() {
       return mapOverlays.size();
    }

    /**
     * Tap that uses int index instead
     * 
     */
    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mapOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(context);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }
    
    /**
     * Adds overlay to list
     * 
     * @param overlay
     */
    public void addOverlay(OverlayItem overlay) {
       mapOverlays.add(overlay);
       this.populate();
    }
}
